<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/yzr_style.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>盘点</title>
</head>
<body>
	<script src="<c:url value="/js/jquery-migrate-1.1.0.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/jquery.jqprint-0.3.js"/>"></script>
<script type="text/javascript">
	$(function(){
		//打开选择药品窗口
		$("#lmb-hcpd-btn").linkbutton({onClick: function(){
			
			var lmb_ck = $("#lmb-pandian-store").combogrid("getValue");
			if(lmb_ck == ''){
				$.messager.alert("提示", "请选择盘点仓库！");
			}else{
				$("#lmb-selectCk-panel").window("open");
				$("#tb-ck-pd_dg").datagrid({
		    		url: 'to_HcByCkId', 
		    		queryParams: {
		    			ckId: lmb_ck
		    		},
		    		method: 'get'
		    	});
			}
			
			
		}});
		
		//显示全部
		$("#lmb-pdck-reload").linkbutton({onClick:function(){
			$("#tb-ck-pd_dg").datagrid({
	    		url: 'to_findAllHcByCkId', 
	    		method: 'get'
	    	});			
		}});
			
		//搜索
		$('#lmb-pdck-search').searchbox({
		    searcher:function(value,name){
		    	if(value == ''){
		    		$.messager.alert("提示", "请输入查询条件！");
		    	}else{
		    		$("#tb-ck-pd_dg").datagrid({	    		
			    		url: 'to_findAllHcByCname',
			    		method: 'post', 
			    		queryParams: {
			    			page:1,
			    			rows:13,
			    			cName: value
			    	}});
		    	}		    	
		    }
		}); 
		
		//耗材编号，药品名，批号，单位，库存数量，结存数量，盈亏数量 
		var lmb_cName = undefined;//耗材名
		var lmb_BatchNum = undefined;//批号
		var lmb_storeNum = undefined;//库存数量
		
		var lmb_cid = undefined;//耗材id
		var lmb_norms = undefined;//单位
		
		//<!--lmb_pd_hcbh, lmb_pd_hcmc, lmb_pd_hcph,lmb_pd_hcdw,lmb_pd_kcsl,lmb_pd_pdsl,lmb_pd_yksl-->
		//确定<!-- cstocCid, cstocCname,cstocBatchNum,cstocNorms,cstocNum-->
		//<!-- lmb_cid,lmb_norms ,lmb-pandian-cname,lmb-pandian-pihao,lmb-pandian-kcnumber,lmb-pandian-jiecunnumber-->
		//lmb-pandian-haocaiId,lmb-pandian-haocaiNorms
		$("#lmb-ok-btn-selectMed").linkbutton({onClick: function(){
			var rows = $("#tb-ck-pd_dg").datagrid("getSelections");
			console.log(rows);
			$("#lmb_hcpd_form").form("validate");
			if(rows.length == 1){
				 lmb_cid = rows[0].cstocCid;
				 lmb_cName = rows[0].cstocCname;
				 lmb_BatchNum = rows[0].cstocBatchNum;
				 lmb_norms = rows[0].cstocNorms;
				 lmb_storeNum = rows[0].cstocNum;
				
				$("#lmb-pandian-cname").textbox("setValue",lmb_cName);
				$("#lmb-pandian-pihao").textbox("setValue",lmb_BatchNum);
				$("#lmb-pandian-kcnumber").textbox("setValue",lmb_storeNum);
				$("#lmb-pandian-haocaiId").textbox("setValue",lmb_cid);
				$("#lmb-pandian-haocaiNorms").textbox("setValue",lmb_norms);
				$("#lmb-selectCk-panel").window("close");
				
				
				lmb_cName = undefined;
				lmb_BatchNum = undefined;
				lmb_storeNum = undefined;
				
				lmb_cid = undefined;
				lmb_norms = undefined;	 
			
			}else{
				$.messager.alert("提示", "您还没有选择记录！");
			}
		}});
		
		var lmb_yinkui = undefined;
		//算出盈亏金额
		$("#lmb-pandian-jiecunnumber").numberbox({onChange: function(){			
			var lmb_a = $("#lmb-pandian-kcnumber").textbox("getValue");
			var lmb_b = $("#lmb-pandian-jiecunnumber").numberbox("getValue");
			if(eval(lmb_a) > eval(lmb_b)){
				lmb_yinkui = lmb_a - lmb_b;
			}else{
				lmb_yinkui = lmb_b - lmb_a;
			}
		}});
		//添加数据到datagrid
		$("#lmb-pd-btn-add").linkbutton({onClick: function(){
			<!-- cidCId, cidCName,cidBatchNum,cidNorms,cidNum,cidPdNum,cidYkNum-->
			//验证表单是否完善
			//盘点
			var lmb_pd_num = $("#lmb-pandian-jiecunnumber").numberbox("getValue");
			if(lmb_storeNum == ''){
				alert("请完善所有数据！");
			}else if(eval(lmb_pd_num)<0){
				$.messager.alert("提示", "盘点数量不能小于0");
			}else{
				//添加行
				$('#lmb-hcpd-dg').datagrid('appendRow',{
					cidCId: $("#lmb-pandian-haocaiId").textbox("getValue"),
					cidCName: $("#lmb-pandian-cname").textbox("getValue"),
					cidBatchNum: $("#lmb-pandian-pihao").textbox("getValue"),
					cidNorms: $("#lmb-pandian-haocaiNorms").textbox("getValue"),
					cidNum:$("#lmb-pandian-kcnumber").textbox("getValue"),
					cidPdNum: $("#lmb-pandian-jiecunnumber").numberbox("getValue"),
					cidYkNum: lmb_yinkui
				});

				//清除部分数据
				$("#lmb-pandian-cname").textbox("clear");
				$("#lmb-pandian-pihao").textbox("clear");
				$("#lmb-pandian-kcnumber").textbox("clear");
				$("#lmb-pandian-haocaiId").textbox("clear");
				$("#lmb-pandian-haocaiNorms").textbox("clear");			
				$("#lmb-pandian-jiecunnumber").numberbox("clear");
				lmb_yinkui = undefined;
			}			
		}});		
		//删除行
		$("#lmb-pd-btn—cancel").linkbutton({onClick: function(){
			var rows = $("#lmb-hcpd-dg").datagrid("getSelections");			
			var lmb_pd_index =$('#lmb-hcpd-dg').datagrid('getRowIndex', rows[0]);
			$('#lmb-hcpd-dg').datagrid('deleteRow',lmb_pd_index);
		}});
		
		
		
		
		//提交数据到数据库//lmb-pandianDet-tijiao
		$("#lmb-pandianDet-tijiao").linkbutton({onClick: function(){
				
			var rows = $("#lmb-hcpd-dg").datagrid("getRows");
			console.log(JSON.stringify(rows));

			//药品编号，药品名称，批号，单位，库存数量，结存数量，盈亏数量
			for(var i = 0; i < rows.length; i ++){
				generateHiddenLmb_pandian(rows[i], "cidCId", i);
				generateHiddenLmb_pandian(rows[i], "cidCName", i);
				generateHiddenLmb_pandian(rows[i], "cidBatchNum", i);
				generateHiddenLmb_pandian(rows[i], "cidNorms", i);
				generateHiddenLmb_pandian(rows[i], "cidNum", i);
				generateHiddenLmb_pandian(rows[i], "cidPdNum", i);
				generateHiddenLmb_pandian(rows[i], "cidYkNum", i);
			}
		
			
			$('#lmb_hcpd_form').form('submit', {
				
				url: 'to_pdHcKc', 
				onSubmit: function(){
					var jg=$('#lmb_hcpd_form').form("validate");
			    	if(jg==false){
			    		$.messager.alert("提示", "请完善所有数据！");
			    		return false;
			    	}
			    }, 
				success: function(v){
					$.messager.alert('提示', "提交成功");
					$(":hidden[x='y']").remove();
					$("#lmb_win-hc-pan-add").window("close");
					$("#lmb-hcpan_dg").datagrid("reload"); 
					$('#lmb_hcpd_form').form("clear");
					$('#lmb-hcpd-dg').datagrid('loadData', { total: 0, rows: [] }); 
				}
			});
		}});

		//创建隐式表单域来保存明细
		function generateHiddenLmb_pandian(row, name, i){
			var lmb_hcpd_form = $('#lmb_hcpd_form');
			//type='hidden'
			$("<input type='hidden' x='y'>")
				.attr("name", "invenDet[" + i + ']' + '.' + name)
				.val(row[name])
				.appendTo(lmb_hcpd_form);
		}	
	});
</script>
<script type="text/javascript">
$(function(){
	$("#lmb—hcpan-add").linkbutton({onClick:function(){						
		$("#lmb_win-hc-pan-add").window("open");
		$("#lmb_hcpd_form").form("clear");
		$('#lmb-hcpd-dg').datagrid('loadData', { total: 0, rows: [] }); 
	}});
	
	//日期转换
	function lmb_todate_pandian(value){
        if(value){
			var date = new Date(value);  
            return date.toLocaleDateString();
		}
    }
	
	//查看计划明细-打印
	$("#lmb—hcpan-ckxq").linkbutton({onClick: function(){
		
		var rows = $("#lmb-hcpan_dg").datagrid("getSelections");
		if(rows.length == 1){	  
			$('#lmb-hcpdDet-window').window("open");
			var ciId = rows[0].ciId;
			//	<!-- lmb-hcpdDet-pddh, lmb-hcpdDet-pdsj,lmb-hcpdDet-pdy,lmb-hcpdDet-pdck-->
			$.getJSON("toLmbfindOneInvent", {"ciId": ciId}, function(data){
				$("#lmb-hcpdDet-pddh").linkbutton({text: data.ciId});
				$("#lmb-hcpdDet-pdsj").linkbutton({text: lmb_todate_pandian(data.ciDate)});
				$("#lmb-hcpdDet-pdy").linkbutton({text: data.pdyName});
				$("#lmb-hcpdDet-pdck").linkbutton({text: data.pdckName});
				
			});	
			
			 //根据id查看详情	
			 $("#lmb-hcpandianDet-dg").datagrid({
				url:'toLmbfindInvenDet',
				width: '100%',
				queryParams:{					
					ciId: ciId
				}
			});
		}else{
			$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
		}
	}});
	
	//点击按钮打印
	$("#lmb-hcpanDet-print").linkbutton({
		onClick: function(){
			$("#lmb-hcpdDet-printArea").jqprint();
		}
	});
	
	// 刷新
	$("#lmb—hcpan-sx").linkbutton({onClick:function(){
		$("#lmb-hcpan_dg").datagrid({
    		url: 'toLmbfindinventByPage', 
    		method: 'get',
    		queryParams:{					
				page: 1,
				rows:5
			}
    	});
	}});
});
</script>
 <table id="lmb-hcpan_dg" class="easyui-datagrid" data-options="
			url:'toLmbfindinventByPage',
			fitColumns:true,fit:true,
			pagination: true,
			pageSize: 5,
			pageList: [5, 10, 15, 20],
			rownumbers: true,
			toolbar: '#lmb—hcpan',
			border:false
			">
		<thead>
			<tr>
				<th data-options="field:'',checkbox:true"></th>
				<th data-options="field:'ciId',width:'30%'">盘点单号</th>
				<th data-options="field:'ciDate', width:'25%',
						formatter:function(value){
                          if(value){
							var date = new Date(value);  
                            return date.toLocaleDateString();
						  }
                 }">盘点日期</th>
                <th data-options="field:'pdyName',width:'24%'">盘点员</th>
				<th data-options="field:'pdckName',width:'20%'">盘点仓库</th>						
			</tr>
		</thead>
	</table>
	
	<div id="lmb—hcpan">
		<a id="lmb—hcpan-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加出库记录</a>
		<a id="lmb—hcpan-ckxq" class="easyui-linkbutton" data-options="iconCls:'icon-xiangqing',plain:true">出库详情</a>
		<a id="lmb—hcpan-sx" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
	</div>
	 
	<div id="lmb_win-hc-pan-add" class="easyui-window" title="录入盘点信息" data-options="collapsible:true,minimizable:false,maximizable:true,modal:true,iconCls:'icon-save',closed: true" style="width:800px;height:320px;padding:5px;">
		<div style="display:none;">
		<input id="lmb-pandian-haocaiId" class="easyui-textbox" 
		data-options="labelAlign:'right',label:'药品编号'"/>
		
		<input id="lmb-pandian-haocaiNorms" class="easyui-textbox" 
		data-options="labelAlign:'right',label:'单位'"/>
	</div>
	
	<form id="lmb_hcpd_form" method="post" style="margin-top:0px;">
		<table width="100%" style="background: rgb(236,243,255); padding: 10px; border-radius: 5px;">
			
			<tr>
				<td style="width:50%;">
					<select id="lmb-pandian-store"  name="invent.ciStorehouse" class="easyui-combogrid"
					data-options="
						label: '盘点仓库',
						labelAlign:'right',
						required:true,
						width: '60%',
						panelWidth: '290',
						panelHeight: 'auto',				
						url: 'queryAllStorehouse',
						pagination: true,
						pageSize: 8,
						pageList: [8, 16, 24, 32],
						idField: 'storeId',
						textField: 'storeName',
						columns: [[
							{field:'storeName',title:'仓库名',width:100},
							{field:'storeKind',title:'类型',width:80},
							{field:'storeAddress',title:'地址 ',width:100}
						]]
					"></select>
				</td>
				<td  style="width:50%;">
					<select id="lmb-pandian-staff" name="invent.ciPeople" class="easyui-combogrid"
					data-options="
							label: '盘点员',
							labelAlign:'right',
							required:true,
							width: '60%',
							panelWidth: '290',
							panelHeight: 'auto',
							url: 'queryAllStaff',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field:'staffName',title:'姓名',width:100},
								{field:'departmentName',title:'部门',width:100},
								{field:'postName',title:'职务',width:85}
							]]
					"></select>
				</td>
			</tr>
			<tr>
				<td style="width:50%;">
					<input  id="lmb-pandian-cname" class="easyui-textbox"  data-options="width:'60%',labelAlign:'right',label:'耗材',readonly:'readonly'">	
					<a id="lmb-hcpd-btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查找</a>				
				</td>
				<td style="width:50%;">
					<input id="lmb-pandian-pihao" class="easyui-textbox"  data-options="width:'60%',labelAlign:'right',label:'批号',readonly:'readonly'">					
				</td>
				
				
			</tr>
			<tr>		
				
				<td style="width:50%;">
					<input id="lmb-pandian-kcnumber" class="easyui-textbox"  data-options="width:'60%',labelAlign:'right',label:'库存数量',readonly:'readonly'">	
				</td>
				<td style="width:50%;">
					<input id="lmb-pandian-jiecunnumber" class="easyui-numberbox"  data-options="width:'60%',labelAlign:'right',label:'盘点数量'">	
					<a id="lmb-pd-btn-add" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a>
					<a id="lmb-pd-btn—cancel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除</a>
				</td>
			</tr>
			
		</table>
		
		<!-- 订单明细 -->
		<div style="margin: 5px;">
			<div id="lmb-hcpd-tabs" class="easyui-tabs" style="width:100%; margin-top:20px;" 
				data-options="plain:true,narrow:true">
				
				<div title="盘点耗材" style="padding:10px;">
					<table id="lmb-hcpd-dg" class="easyui-datagrid" 
							data-options="
								iconCls: 'icon-edit',									
								width: '100%',
								toolbar: '#lmb_pdtj_tb1',
								pagination: true,						
								pageSize: 8,
								pageList: [8, 16, 24, 32],
								">
							<thead>
								<tr>	
									<th data-options="field:'cidCId',width:'20%',align:'center'">耗材编号</th>			
									<th data-options="field:'cidCName',width:'18%',align:'center'">耗材名称</th>
									<th data-options="field:'cidBatchNum',width:'14%',align:'center'">批号</th>
									<th data-options="field:'cidNorms',width:'12%',align:'center'">单位</th>
									<th data-options="field:'cidNum',width:'12%',align:'center'">库存数量</th>
									<th data-options="field:'cidPdNum',width:'12%',align:'center'">盘点数量</th>
									<th data-options="field:'cidYkNum',width:'12%',align:'center'">盈亏数量</th>
								</tr>
							</thead>
					 </table>
					 <div id="lmb_pdtj_tb1" style="height:auto">
							<a id="lmb-pandianDet-tijiao" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-ok'">提交</a>			
					</div>
				</div>							
			</div>						
		</div>
	</form>
	
	
	<!-- 选择盘点药品窗口 -->
	<div id="lmb-selectCk-panel" class="easyui-window" title="选择盘点耗材" style="width:850px;height:350px;" data-options="closable:true,closed:true,collapsible:false,minimizable:false,maximizable:false">
		<table id="tb-ck-pd_dg" class="easyui-datagrid" 
			data-options="			
				fit:true,
				pagination: true,
				pageSize: 8,
				pageList: [8, 16, 24, 32],
				rownumbers: false,
				toolbar: '#lmb-toolbar-pdck',
				border:false,
				singleSelect:true
			">
			<thead>
				<tr>					
					<th data-options="field:'ckName',width:'20%',align:'center',editor:'textbox'">仓库</th>				
					<th data-options="field:'cstocCid',width:'20%',align:'center',editor:'textbox'">耗材编号</th>				
					<th data-options="field:'cstocCname',width:'20%',align:'center'">耗材名称</th>
					<th data-options="field:'cstocBatchNum',width:'13%',align:'center'">批号</th>					
					<th data-options="field:'cstocNorms',width:'13%',align:'center'">单位</th>	
					<th data-options="field:'cstocNum',width:'13%',align:'center'">数量</th>																								
				</tr>
			</thead>
		</table>				    
	    
	    <!-- 工具栏 -->
	    <div id="lmb-toolbar-pdck">
	    	<input id="lmb-pdck-search" class="easyui-searchbox" data-options="menu: '#lmb-pdck—serch', width: 250, prompt: '请输入关键字'"/>    	
	    	<a id="lmb-pdck-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
	    	<a id="lmb-ok-btn-selectMed" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定</a>
	    </div>
	    	    
	    <!-- 搜索框 -->
	    <div id="lmb-pdck—serch" style="width:120px">
	    	<div data-options="name:'cName'">耗材名称</div>
		</div>		
	</div>			
	</div>
	
	<!--查看详情窗口-打印 -->
	<div id="lmb-hcpdDet-window" class="easyui-window" title="采购计划详情" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:70%;height:70%;">		
		<div class="easyui-layout" style="padding:0px;" data-options="fit:true">			
			<div id="lmb-hcpdDet-printArea" data-options="region:'center'" style="padding:5px;border-top:none;border-left:none;border-right:none;">			
				<form id="lmb_hcpandianDet_form" method="post">
					<h1 style="text-align: center">耗材采购计划</h1>
					<table width="100%">		
						<tr>
							<td>盘点单号: <a id="lmb-hcpdDet-pddh"  name="ciId"     class="easyui-linkbutton" data-options="plain:true,"></a></td>
							<td>盘点时间:  <a id="lmb-hcpdDet-pdsj" name="ciDate"        class="easyui-linkbutton" data-options="plain:true"></a></td>			
							<td>盘点员:  <a id="lmb-hcpdDet-pdy"    name="pdyName"  class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>盘点仓库: <a id="lmb-hcpdDet-pdck"  name="pdckName"   class="easyui-linkbutton" data-options="plain:true"></a></td>
						</tr>
					</table>
						
					<div style="margin: 5px;">
						<table id="lmb-hcpandianDet-dg" class="easyui-datagrid" 
							data-options="
								iconCls: 'icon-edit',
								singleSelect: true,										
								width: '100%'						
						">			
							<thead>
								<tr>	
									<th data-options="field:'cidId',width:'18%',align:'center'">盘点详情编号</th>	
									<th data-options="field:'cidCId',width:'15%',align:'center'">耗材编号</th>					
									<th data-options="field:'cidCName',width:'16%',align:'center'">耗材名称</th>
									<th data-options="field:'cidBatchNum',width:'10%',align:'center'">批号</th>
									<th data-options="field:'cidNorms',width:'10%',align:'center'">单位</th>
									<th data-options="field:'cidPdNum',width:'10%',align:'center'">库存数量</th>
									<th data-options="field:'cidNum',width:'10%',align:'center'">盘点</th>
									<th data-options="field:'cidYkNum',width:'10%',align:'center'">盈亏数量</th>
								</tr>
							</thead>
						</table>									
					</div>
				</form>				
			</div>
					
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="lmb-hcpanDet-print"  class="easyui-linkbutton" data-options="iconCls:'icon-print', plain:true">打印</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#lmb-hcpdDet-window').window('close');">取消</a>
			</div>			
		</div>
	</div>
</body>
</html>